﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.SignalR;

namespace OA.Mvc.Chats
{
    public class TestSignalR : PersistentConnection
    {
        static int count = 0;
        protected override Task OnConnected(IRequest request, string connectionId)
        {
            Interlocked.Increment(ref count); // 利用锁的机制改变资源
           
            // 发送消息
            return Connection.Send(connectionId, "Welcome!当前人数："+count);
        }

        protected override Task OnReceived(IRequest request, string connectionId, string data)
        {
            // 广播
            return Connection.Broadcast(connectionId+"发送新消息：" +data);
        }
    }
}